1.Activar las librerías

library(ggplot2) #Gráficas más bonitas
library(plotly) #Gráficas interactivas
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggmap) #Mapas
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
## 
## Attaching package: 'ggmap'
## The following object is masked from 'package:plotly':
## 
##     wind

Gráfica de una función cúbica

2. Definimos un dominio x para nuestras funciones

x<-(-10:10)
x
##  [1] -10  -9  -8  -7  -6  -5  -4  -3  -2  -1   0   1   2   3   4   5   6   7   8
## [20]   9  10

3. Elegir la función que queremos graficar: j(x)=5x^3

jx<-5*x^3
plot(x,jx, main="Función cúbica", xlab="Eje x", ylab="Eje y", col="purple", type="o")

Este vídeo te puede ayudar a comprender mejor el tema…

Mapas en R

Debemos crear nuestros datos

Para realizar mapas en R, primero debemos de crear nuestros datos.

Akira<-c(-100.30925, 25.6714 )
Anahí<-c(-86.84656,21.17429)
Joyce<-c( -86.801667,21.387222)
Sveydy<-c(-103.39182,20.66682)
ubicación<-rbind(Akira,Anahí,Joyce,Sveydy)
ubicación
##              [,1]     [,2]
## Akira  -100.30925 25.67140
## Anahí   -86.84656 21.17429
## Joyce   -86.80167 21.38722
## Sveydy -103.39182 20.66682

Ahora que tenemos nuestros datos, cambiaremos el nombre de nuestras columnas con la función colnames:

colnames(ubicación)<-c("Longitud","Latitud")
ubicación
##          Longitud  Latitud
## Akira  -100.30925 25.67140
## Anahí   -86.84656 21.17429
## Joyce   -86.80167 21.38722
## Sveydy -103.39182 20.66682

Transformamos nuestra matriz en un data.frame

ubicación<-data.frame(ubicación)
ubicación
##          Longitud  Latitud
## Akira  -100.30925 25.67140
## Anahí   -86.84656 21.17429
## Joyce   -86.80167 21.38722
## Sveydy -103.39182 20.66682

Creamos una grafica de dispersión

dispersion<-ggplot(ubicación)+geom_text(aes(Latitud,Longitud),label= rownames(ubicación))+geom_point(aes(Latitud,Longitud),color= rainbow(4))
ggplotly(dispersion)

Creamos un mapa con la funcion qmplot

qmplot(Longitud, Latitud, data=ubicación, color=I(rainbow(4)))

Mapa de puntos y densidad

Al agregar el parámetro geom = c("point","density2d") podemos hacer un mapa de puntos y densidad:

qmplot(Longitud, Latitud, data=ubicación, geom=c("point","density2d"))